//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package location;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import common.GlobalID;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class DisplayProductionObject {
    private final int Instance;
    private final int ID;
    private int Rank;
    private int GatheredResource;
    private final List<DisplayProductionObject.productionWithTimer> FinishedProductions = new ArrayList();
    private final List<DisplayProductionObject.productionWithTimer> Productions = new ArrayList();
    private final List<Integer> RemovedProductions = new ArrayList();
    private final List<Integer> finishedIndex = new ArrayList();
    private final List<Integer> removedIndex = new ArrayList();
    private Integer X = null;
    private Integer Y = null;
    private Boolean mirrored = null;
    private Integer currentStage = Integer.valueOf(0);

    public void clearLists() {
        this.FinishedProductions.clear();
        this.Productions.clear();
        this.RemovedProductions.clear();
        this.finishedIndex.clear();
        this.removedIndex.clear();
    }

    public DisplayProductionObject(int id, int rank, int instance) {
        this.ID = id;
        this.Rank = rank;
        this.Instance = instance;
    }

    public int getProductionInstanceGlobalID() {
        return GlobalID.create(GlobalID.getClassID(this.ID), this.Instance);
    }

    public int id() {
        return this.ID;
    }

    public int rank() {
        return this.Rank;
    }

    public void setRank(int rank) {
        this.Rank = rank;
    }

    public void setGatheredResource(int val) {
        this.GatheredResource = val;
    }

    public int getGatheredResource() {
        return this.GatheredResource;
    }

    public int getEmptySlotsCount() {
        return this.Rank - this.FinishedProductions.size() - this.Productions.size() - this.RemovedProductions.size();
    }

    public int getReadySlotsCount() {
        return this.FinishedProductions.size();
    }

    public int getInprogressCount() {
        return this.Productions.size();
    }

    public void speedup(int ticksNow) {
        boolean doupdate = false;
        if(this.Productions.size() > 0) {
            DisplayProductionObject.productionWithTimer p = (DisplayProductionObject.productionWithTimer)this.Productions.get(0);
            if(p.timer != null && p.timer.getRmainingSeconds(ticksNow) > 0) {
                p.timer.reset();
                doupdate = true;
            }
        }

        if(doupdate) {
            this.updateTicksLeft(ticksNow);
        }

    }

    public void updateTicksLeft(int ticksNow) {
        if(this.Productions.size() > 0) {
            DisplayProductionObject.productionWithTimer p = (DisplayProductionObject.productionWithTimer)this.Productions.get(0);
            if(p.timer.getRmainingSeconds(ticksNow) == 0) {
                this.Productions.remove(p);
                this.FinishedProductions.add(p);
            }
        }

    }

    public void updateTicksLeftAll(int ticksNow) {
        ArrayList needToRemove = new ArrayList();

        for(int p = 0; p < this.Productions.size(); ++p) {
            DisplayProductionObject.productionWithTimer p1 = (DisplayProductionObject.productionWithTimer)this.Productions.get(p);
            if(p1.timer.getRmainingSeconds(ticksNow) == 0) {
                this.FinishedProductions.add(p1);
                needToRemove.add(p1);
            }
        }

        Iterator var6 = needToRemove.iterator();

        while(var6.hasNext()) {
            DisplayProductionObject.productionWithTimer var5 = (DisplayProductionObject.productionWithTimer)var6.next();
            this.Productions.remove(var5);
        }

    }

    public void addProductionTimer(int id, DisplayObjectTimer timer) {
        if(this.Productions.size() == this.Rank) {
            System.out.println(this.getClass().getName() + ": Productions.size() == Rank\n");
        }

        DisplayProductionObject.productionWithTimer newprod = new DisplayProductionObject.productionWithTimer(id, timer);
        this.Productions.add(newprod);
    }

    public void addFinished(int id) {
        this.FinishedProductions.add(new DisplayProductionObject.productionWithTimer(id, (DisplayObjectTimer)null));
    }

    public void addRemoved(int id) {
        this.RemovedProductions.add(Integer.valueOf(id));
    }

    public void addFinishedIndex(int id) {
        this.finishedIndex.add(Integer.valueOf(id));
    }

    public void addRemovedIndex(int id) {
        this.removedIndex.add(Integer.valueOf(id));
    }

    public List<Integer> climeReady(int climeMax) {
        ArrayList val = new ArrayList();
        ArrayList retval = new ArrayList();

        for(int pwt = 0; pwt < climeMax && pwt < this.FinishedProductions.size(); ++pwt) {
            val.add((DisplayProductionObject.productionWithTimer)this.FinishedProductions.get(pwt));
        }

        Iterator var5 = val.iterator();

        while(var5.hasNext()) {
            DisplayProductionObject.productionWithTimer var6 = (DisplayProductionObject.productionWithTimer)var5.next();
            retval.add(Integer.valueOf(var6.id));
            this.FinishedProductions.remove(var6);
        }

        return retval;
    }

    public void climeReady(int climeMax, List<Integer> products, List<Integer> indexes) {
        ArrayList val = new ArrayList();
        products.clear();
        indexes.clear();

        for(int idx = 0; idx < climeMax && idx < this.FinishedProductions.size(); ++idx) {
            val.add((DisplayProductionObject.productionWithTimer)this.FinishedProductions.get(idx));
            indexes.add((Integer)this.finishedIndex.get(idx));
        }

        Iterator var6 = val.iterator();

        while(var6.hasNext()) {
            DisplayProductionObject.productionWithTimer var7 = (DisplayProductionObject.productionWithTimer)var6.next();
            products.add(Integer.valueOf(var7.id));
            this.FinishedProductions.remove(var7);
        }

        var6 = indexes.iterator();

        while(var6.hasNext()) {
            Integer var8 = (Integer)var6.next();
            this.finishedIndex.remove(var8);
        }

    }

    public Integer getGoodsCount(Integer goodid) {
        Integer count = Integer.valueOf(0);
        Iterator var4 = this.FinishedProductions.iterator();

        DisplayProductionObject.productionWithTimer pwt;
        while(var4.hasNext()) {
            pwt = (DisplayProductionObject.productionWithTimer)var4.next();
            if(pwt.id == goodid.intValue()) {
                count = Integer.valueOf(count.intValue() + 1);
            }
        }

        var4 = this.Productions.iterator();

        while(var4.hasNext()) {
            pwt = (DisplayProductionObject.productionWithTimer)var4.next();
            if(pwt.id == goodid.intValue()) {
                count = Integer.valueOf(count.intValue() + 1);
            }
        }

        return count;
    }

    public Integer getStage() {
        return this.currentStage;
    }

    public void setStage(Integer stage) {
        this.currentStage = stage;
    }

    public Integer X() {
        Integer val = Integer.valueOf(0);
        if(this.X != null) {
            val = this.X;
        }

        return val;
    }

    public Integer Y() {
        Integer val = Integer.valueOf(0);
        if(this.Y != null) {
            val = this.Y;
        }

        return val;
    }

    public void setX(Integer x) {
        this.X = x;
    }

    public void setY(Integer y) {
        this.Y = y;
    }

    public Boolean getMirrored() {
        Boolean val = Boolean.valueOf(false);
        return this.mirrored != null?this.mirrored:val;
    }

    public void setMirroed(Boolean mirrored) {
        this.mirrored = mirrored;
    }

    public JsonObject getAsJsonObject() {
        JsonObject jo = new JsonObject();
        jo.addProperty("Rank", Integer.valueOf(this.Rank));
        JsonArray jaProd = new JsonArray();
        JsonArray jaFinished = new JsonArray();
        DisplayProductionObject.productionWithTimer jpo;
        Iterator var5;
        JsonObject jpo1;
        if(this.Productions.size() > 0) {
            var5 = this.Productions.iterator();

            while(var5.hasNext()) {
                jpo = (DisplayProductionObject.productionWithTimer)var5.next();
                jpo1 = new JsonObject();
                jpo1.addProperty("ID", Integer.valueOf(jpo.id));
                jpo1.add("Timer", jpo.timer.getAsJsonObject());
                jaProd.add(jpo1);
            }
        }

        if(this.FinishedProductions.size() > 0) {
            var5 = this.FinishedProductions.iterator();

            while(var5.hasNext()) {
                jpo = (DisplayProductionObject.productionWithTimer)var5.next();
                jpo1 = new JsonObject();
                jpo1.addProperty("ID", Integer.valueOf(jpo.id));
                jaFinished.add(jpo1);
            }
        }

        if(jaProd.size() > 0 || jaFinished.size() > 0) {
            JsonObject jpo2 = new JsonObject();
            if(jaProd.size() > 0) {
                jpo2.add("Productions", jaProd);
            }

            if(jaFinished.size() > 0) {
                jpo2.add("FinishedProductions", jaFinished);
            }

            jo.add("ProductionList", jpo2);
        }

        return jo;
    }

    public String toString() {
        String retval = "{ ID:" + this.ID + ", Rank:" + this.Rank + "\n      Productions:[";
        if(this.Productions.size() > 0) {
            retval = retval + "\n";
        }

        DisplayProductionObject.productionWithTimer key;
        Iterator var3;
        for(var3 = this.Productions.iterator(); var3.hasNext(); retval = retval + "          { ID:" + key.id + " " + key.timer + " }\n") {
            key = (DisplayProductionObject.productionWithTimer)var3.next();
        }

        retval = retval + "      ]\n      FinishedProductions:[";
        if(this.FinishedProductions.size() > 0) {
            retval = retval + "\n";
        }

        for(var3 = this.FinishedProductions.iterator(); var3.hasNext(); retval = retval + "          { ID:" + key.id + " }\n") {
            key = (DisplayProductionObject.productionWithTimer)var3.next();
        }

        if(GlobalID.getClassID(this.ID) == 62) {
            retval = retval + "      ]\n      RemovedProductions:[";

            Integer key1;
            for(var3 = this.RemovedProductions.iterator(); var3.hasNext(); retval = retval + "          { ID:" + key1 + " }\n") {
                key1 = (Integer)var3.next();
            }
        }

        retval = retval + "      ]\n}\n";
        return retval;
    }

    private class productionWithTimer {
        public final int id;
        public final DisplayObjectTimer timer;

        public productionWithTimer(int id, DisplayObjectTimer timer) {
            this.id = id;
            this.timer = timer;
        }
    }
}
